﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using FubiManger.Controls;
using Model;

namespace FubiManger.UI
{
    partial class SpecsFrom : Smobiler.Core.Controls.MobileForm
    {
        public SpecsFrom() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        /// <summary>
        /// 规格集合
        /// </summary>
        public  List<specs> splist { get; set; }
        bool flag = false;
        private void panclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }


        private void panadd_Press(object sender, EventArgs e)
        {
            if (flag == false)
            {
                flag = true;
                panspecs.Height = (splist.Count + 1) * 32;
                pan_specs.Height = 27 + panspecs.Height;
                specscontrol con = new specscontrol();
                panspecs.Controls.Add(con);
            }
            else
            {
                MessageBox.Show("有参数并未保存");
            }

        }
        /// <summary>
        /// 设置规格
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public void Setspecs(string key, string value)
        {
            flag = false;
            specs sp = new specs();
            sp.key = key;
            sp.value = value;
            splist.Add(sp);
            
        }
        public void Delspecs(int index)
        {
            if (splist.Count > 0)
            {
                splist.RemoveAt(index);
                panspecs.Height = splist.Count * 32;
                pan_specs.Height = 27 + panspecs.Height;
                for (int i = 0; i < splist.Count; i++)
                {
                    specscontrol con = new specscontrol();
                    con.key = splist[i].key;//规格名
                    con.value = splist[i].value;//参数
                    con.index = i;//编号
                    con.stype = "2";//2显示
                    panspecs.Controls.Add(con);
                }
            }
        }
        private void SpecsFrom_Load(object sender, EventArgs e)
        {
            if (splist != null)
            {
                panspecs.Height = splist.Count * 32;
                pan_specs.Height = 27 + panspecs.Height;
                for (int i = 0; i < splist.Count; i++)
                {
                    specscontrol con = new specscontrol();
                    con.key = splist[i].key;//规格名
                    con.value = splist[i].value;//参数
                    con.index = i;//编号
                    con.stype = "2";//2显示
                    panspecs.Controls.Add(con);
                }
            }
            else
                splist = new List<specs>();
        }
    }
}